package com.xd.clap.controller;

import com.xd.clap.entity.Product;
import com.xd.clap.entity.request.PageParam;
import com.xd.clap.entity.response.Result;
import com.xd.clap.services.ProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ProductService ps;

    /**
     * 查询全部商品
     */
    @GetMapping("/getProductPage")
    public Result getProductPage(PageParam pageParam) {
        return ps.getProductPage(pageParam);
    }

    /**
     * 根据id查询商品
     */
    @GetMapping("/getProduct")
    public Result getProductById(Product product) {
        return ps.getProductById(product.getId());
    }

    /**
     *修改和删除商品
     */
    @PutMapping("/updateProduct")
    public Result updateProduct(@RequestBody Product product) {
        return ps.updateProduct(product);
    }

    /**
     * 删除商品信息
     */
    @DeleteMapping("/deleteProduct")
    public Result deleteProduct(Product product) {
        return ps.deleteProduct(product.getId());
    }


    /**
     * 更新上架
     */
    @PutMapping("/updateShow")
    public Result updateShow(@RequestBody Product product){
        return ps.updateShow(product);
    }
}
